package com.lovo.middleman.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lovo.middleman.bean.CustomerBean;
import com.lovo.middleman.bean.SupplierBean;
import com.lovo.middleman.mapper.CustomerMapper;
import com.lovo.middleman.service.ICustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, CustomerBean> implements ICustomerService {

    @Autowired
    CustomerMapper customerMapper;

    @Override
    public List<CustomerBean> queryCustomerBean() {
        QueryWrapper<CustomerBean> queryWrapper = new QueryWrapper<>();
        queryWrapper.gt("customer_id", 0);
        return customerMapper.selectList(queryWrapper);
    }

    @Override
    public Page<CustomerBean> selectCustomerPageItem(int curPage,
                                                         int pageSize,
                                                         String customerName,
                                                         String customerBusinessScope) {

        QueryWrapper<CustomerBean> queryWrapper = new QueryWrapper<>();
        if (customerName != null && !"".equals(customerName)) {
            queryWrapper.like("customer_name", customerName);

        }
        if (customerBusinessScope != null && !"".equals(customerBusinessScope)) {
            queryWrapper.like("customer_business_scope", customerBusinessScope);
        }

        return customerMapper.selectPage(new Page<>(curPage,pageSize),queryWrapper);
    }

    @Override
    public CustomerBean selectById(int id) {
        return  customerMapper.selectById(id);

    }

    @Override
    public void updateCustomer(CustomerBean customerBean) {
        customerMapper.updateById(customerBean);
    }

    @Override
    public void addCustomer(CustomerBean customerBean) {
        customerMapper.insert(customerBean);
    }

    @Override
    public List<CustomerBean> addCustomerBean(List<CustomerBean> customerBeanList) {
        return null;
    }
}
